home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10340 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: bitfields, how big can their elements be?
  5. Date: Sat, 16 Mar 96 22:38:18 GMT
  6. Organization: none
  7. Message-ID: <827015898snz@genesis.demon.co.uk>
  8. References: <4i2lab$ili@hobbes.cc.uga.edu> <TANMOY.96Mar12075107@qcd.lanl.gov> <4i4c8dINNsde@keats.ugrad.cs.ubc.ca> <4icc3a$g9i@airdmhor.gen.nz>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <4icc3a$g9i@airdmhor.gen.nz>
  15.            gumboot@airdmhor.gen.nz "Simon Hosie" writes:
  16.  
  17. >Kazimir Kylheku:
  18. >> With GCC I tried making bitfields "long" and "short". This is an odd
  19. > locution;
  20. >> the compiler will actually prevent a "short" field from being more than 16
  21. >> bits, but long can be 32. It's strange that the GNU compiler allows these
  22. >> modifiers for bitfields! I'm going to have to look this up in the standard
  23. > the
  24. >> first chance I get.
  25.  
  26. The standard says (6.5.2.1):
  27.  
  28. "A bit-field shall have a type that is a qualified or unqualified version of
  29.  one of int, unsigned int, or signed int."
  30.  
  31. However this isn't in a constraints section so a "long" or "short" bitfield
  32. results in undefined behaviour but the compiler is not required to issue
  33. a diagnostic. Therefore this is a legitimate candidate for a compiler
  34. defined language extension.
  35.  
  36. >  I'm fairly certain that they're supposed to be limited to 
  37. >(CHAR_BIT * sizeof(int)) bits.
  38.  
  39. If the code follows the standard (which implies that you are using int,
  40. unsigned int or signed int) then that is correct. Once you march off into
  41. undefined behaviour the compiler can extend the language with whatever rules
  42. it likes. (Actually I'm going to query that in comp.std.c since there is
  43. also a constraint applicable here).
  44.  
  45. -- 
  46. -----------------------------------------
  47. Lawrence Kirby | fred@genesis.demon.co.uk
  48. Wilts, England | 70734.126@compuserve.com
  49. -----------------------------------------
  50.